package com.study.english.controller;

import cn.hutool.core.io.FileUtil;
import com.study.english.result.Result;
import org.apache.ibatis.executor.ResultExtractor;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;


@RestController
@RequestMapping("simpleUploadFile")
public class SimpleUploadController {

    @PostMapping("/upload")
    public Result upload(MultipartFile file) {
        try {
            //创建临时文件夹
            UUID uuid = UUID.randomUUID();
            Path pathTemp = Files.createTempDirectory("examTemplateOne" + "-" + uuid.toString());
            File uploadDir = pathTemp.toFile();
            uploadDir.deleteOnExit();
            // 指定目录，这里假设是在服务器运行路径下的uploads文件夹
            Path path = Paths.get(uploadDir.getPath() + file.getOriginalFilename());
            // 保存文件
            Files.copy(file.getInputStream(), path);
        } catch (Exception e) {
        }
        return Result.success("上传成功");
    }
}
